#ifndef XGE_UNITTEST_MAINLOOP_H_
#define XGE_UNITTEST_MAINLOOP_H_

#include "xge_common_config.h"

#include "scene_mgr.h"
#include "event_base.h"
#include "xassert.h"
#include "xmainloop.h"
#include "graphics_window.h"
#include "xge.h"

#include <stdio.h>

using namespace xge;
using namespace xge::xge_internal;
using namespace xge::event;
using namespace xge::graphics;
using namespace xge::window;


// A testing event 
class MyEvent : public Event {
public:

  MyEvent() : Event(5){}

  virtual void OnLoop( const Timer::tick_t& time ) {
    printf("I am in the loop :%f\n", time.ToSecond() );
    if( life_time() == 1 ) {
      XGameEngine::GetMainLoop()->QuitApplication();
    }
  }

  virtual bool Reset() {
    // do nothing 
    return true;
  }
};

// On Exit Listener 
class MyOnExit : public OnExitListener {
public:
  virtual void OnExit() {
    printf("I am on exit now");
    ::getchar();
  }


};




UNIT_TEST(MainLoop,Case1) {

  XASSERT(XGameEngine::CreateGameEngine( 800, 600 , false, _xT("XGameText") ));

  MainLoop* loop = XGameEngine::GetMainLoop();

  MyEvent* eve = new MyEvent();
  MyOnExit* on_e = new MyOnExit();
  XGameEngine::GetEventManager()->AddEvent( eve );
  eve->Drop();
  // set  up the listener
  XGameEngine::GetGraphics2D()->GetGraphicsWindow()->set_on_exit_listener( on_e );
  on_e->Drop();

  // Now the memory should have been deleted automatically here 
  loop->Loop();


}






#endif// XGE_UNITTEST_MAINLOOP_H_